/***********************************************************************
 * BinTrotter : BitTorrent library/client for the Android operating system.
 *  
 * Copyright (C) 2009, Christopher David Stones (chris.stones@gmail.com)
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 ***********************************************************************/

package org.bintrotter;

import java.util.Random;

public class ClientInfo {

	public String peer_id;
	public int	  port;
	
	public static final int VERSION_MAJOR = 0;
	public static final int VERSION_MINOR = 1;
	public static final int VERSION_REVISION = 0;
	
	public static ClientInfo instance() {
		
		if(singleton == null)
			singleton = new ClientInfo();
		
		return singleton;
	}
	
	private static ClientInfo singleton = null;
	
	protected ClientInfo() {
		
		port = 0;// 6881;
		
		Main.log.info("bin-trotter-" + VERSION_MAJOR + "." + VERSION_MINOR + "." + VERSION_REVISION);
		
		setPeerId();
	}
	
	protected void setPeerId() {
		
		/*** peer id http://forums.degreez.net/viewtopic.php?t=7070 ***/
		String chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxzy.-";
		
		StringBuilder sb = new StringBuilder();
	
		sb.append("B");
		sb.append(chars.charAt(VERSION_MAJOR 		/ 16));
		sb.append(chars.charAt(VERSION_MAJOR 		% 16));
		sb.append(chars.charAt(VERSION_MINOR 		/ 16));
		sb.append(chars.charAt(VERSION_MINOR 		% 16));
		sb.append(chars.charAt(VERSION_REVISION		% 16));
		sb.append("000");

		Random r = new Random();
		for(int i=9; i<20; ++i)
			sb.append(chars.charAt(r.nextInt(chars.length())));
		
		peer_id = sb.toString();
		
		Main.log.info("peer_id: " + peer_id);
		
	}

	public int staticRequestLength() {
		
		return 16384;
	}

	public int requestQueueLength() {

		return 5;
	}
}

